package edu.cicese.alz.swing;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.border.EmptyBorder;
import java.awt.Color;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 7/06/12
 * Time: 03:02 PM
 */
public class CustomToggleButton extends JButton {
	private boolean selected = false;
	private Color bgColor;
	private boolean pressed = false;

	public CustomToggleButton(boolean selected, Color bgColor) {
		super();
		setSelected(selected);
		this.bgColor = bgColor;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
		if (selected) {
			paintSelected();
		}
		else {
			paintDeselected();
		}
	}

	public void paintSelected() {
		setBackground(SwingUtil.cPressed);
		setBorder(BorderFactory.createLineBorder(SwingUtil.cPressedBorder));
	}

	public void paintDeselected() {
		setBackground(bgColor);
		setBorder(new EmptyBorder(1, 1, 1, 1));
	}

	public void paintRollover() {
		setBackground(SwingUtil.cRollover);
		setBorder(BorderFactory.createLineBorder(SwingUtil.cRolloverBorder));
	}
//
//	public void select() {
//		setSelected(true);
//		paintSelected();
//	}
//
//	public void deselect() {
//		setSelected(false);
//		paintDeselected();
//	}

	public boolean isPressed() {
		return pressed;
	}

	public void setPressed(boolean pressed) {
		this.pressed = pressed;
	}
}

